###########################
# Anglo-Afghan War
###########################
# By DoctorPainkiller
###########################

add_namespace = afghanistan_events

# 5th Anglo-Afghan War
country_event = { #attack Delhi
	id = afghanistan_events.0
	title = afghanistan_events.0.t
	desc = afghanistan_events.0.d
	picture = GFX_report_event_british_artillery


	is_triggered_only = yes

	option = {
		log = "[GetLogInfo]: event afghanistan_events.0 option afghanistan_events.0.a"
		name = afghanistan_events.0.a
		ai_chance = {
			base = 100
			modifier = {
				factor = 0
				has_game_rule = { rule = AFG_war option = AFG_WAR_NO }
			}
		}
		set_global_flag = RAJ_afghan_war
		add_manpower = 20000
		declare_war_on = {
			target = RAJ
			type = annex_everything
		}
		add_named_threat = {
			threat = 1
			name = AFG_anglo_afghan_war_threat
		}
		add_timed_idea = {
    			idea = AFG_unexpected_strike
    			days = 15
		}
		RAJ = {
			add_timed_idea = {
    				idea = AFG_unexpected_strike_raj_side
    				days = 7
			}
		}
		hidden_effect = {
			add_ideas = has_scripted_peace
			RAJ = {
				country_event = { id = afghanistan_events.1 days = 1 }
			}
			country_event = { id = afghanistan_events.10 days = 5 random_days = 36 }
			country_event = { id = afghanistan_events.24 days = 10 random_days = 36 }
			news_event = { id = afghanistan_events.30 days = 1 }
		}
	}

	option = {
		log = "[GetLogInfo]: event afghanistan_events.0 option afghanistan_events.0.b"
		name = afghanistan_events.0.b
		ai_chance = {
			base = 0
			modifier = {
				add = 100
				has_game_rule = { rule = AFG_war option = AFG_WAR_NO }
			}
		}
		add_stability = -0.10
	}
}

# RAJ war notification event
country_event = {
	id = afghanistan_events.1
	title = afghanistan_events.1.t
	desc = afghanistan_events.1.d
	picture = GFX_report_event_RAJ_soldiers_in_afghanistan

	fire_only_once = yes

	is_triggered_only = yes

	option = {
		log = "[GetLogInfo]: event afghanistan_events.1 option afghanistan_events.1.a"
		name = afghanistan_events.1.a
		effect_tooltip = {
			add_timed_idea = {
    				idea = AFG_unexpected_strike_raj_side
    				days = 7
			}
		}
	}
}

# Afghanistan wins, chooses demands to send to RAJ
country_event = {
	id = afghanistan_events.2
	title = afghanistan_events.2.t
	desc = afghanistan_events.2.d
	picture = GFX_report_event_PRF_war

	fire_only_once = yes

	trigger = {
		tag = AFG
		is_valid_peace_target = yes
		has_global_flag = RAJ_afghan_war
		surrender_progress < 0.2
		OR = {
			RAJ = {
				has_war_with = ROOT
				surrender_progress > 0.8
			}
			AND = {
				NOT = { country_exists = RAJ }
				owns_state = 443 #Sind
			}
			AND = {
				controls_state = 443
				RAJ = { 
					has_war_with = ROOT
					surrender_progress > 0.6
				}
			}
			AND = {
				controls_state = 891
				RAJ = { 
					has_war_with = ROOT
					surrender_progress > 0.6
				}
			}
		}
	}

	mean_time_to_happen = {
		days = 10
	}

	immediate = {
		hidden_effect = {
			country_event = { id = afghanistan_events.25 days = 20 random_days = 100 }
		}
		set_global_flag = AFG_won_fifth_war
	}

	option = {
		log = "[GetLogInfo]: event afghanistan_events.2 option afghanistan_events.2.a"
		name = afghanistan_events.2.a #We shall demand the liberation of Quetta
		add_state_core = 445 #Quetta
	}
	option = {
		log = "[GetLogInfo]: event afghanistan_events.2 option afghanistan_events.2.b"
		name = afghanistan_events.2.b #Demand both Quetta and Baluchistan
		ai_chance = { base = 0 }
		add_political_power = -100
		add_stability = -0.1
		add_state_core = 444 #Baluchistan
		add_state_core = 445 #Quetta
	}
	option = {
		log = "[GetLogInfo]: event afghanistan_events.2 option afghanistan_events.2.c"
		name = afghanistan_events.2.c #Demand them both, and lay claim to even more!
		ai_chance = { base = 0 }
		add_stability = -0.20
		add_political_power = -200
		add_state_core = 444 #Baluchistan
		add_state_core = 445 #Quetta
		443 = { add_claim_of_ROOT = yes } #Sind
		433 = { add_claim_of_ROOT = yes } #Rajputana
		440 = { add_claim_of_ROOT = yes } #East Punjab
		891 = { add_claim_of_ROOT = yes } #West Punjab
		441 = { add_claim_of_ROOT = yes } #Kashmir
		890 = { add_claim_of_ROOT = yes } #Simla
	}
	after = {
		if = {
			limit = { has_war_with = RAJ }
			RAJ = { country_event = afghanistan_events.3 }
		}
	}
}

# RAJ receives the peace demand
country_event = {
	id = afghanistan_events.3
	title = afghanistan_events.3.t
	desc = afghanistan_events.3.d
	picture = GFX_report_event_PRF_war

	is_triggered_only = yes

	immediate = {
		if = {
			limit = { is_in_faction = yes }
			faction_leader = { save_event_target_as = white_peace_receiver }
		}
		else_if = {
			limit = { is_subject = yes }
			overlord = { save_event_target_as = white_peace_receiver }
		}
		else = {
			save_event_target_as = white_peace_receiver
		}
	}

	option = {
		log = "[GetLogInfo]: event afghanistan_events.3 option afghanistan_events.3.a"
		name = afghanistan_events.3.a #We yield because we have no other choice...
		every_owned_state = {
			limit = { is_core_of = FROM }
			transfer_state_to = FROM
		}
		FROM = {
			white_peace_with_TARGET = yes
			country_event = { id = afghanistan_events.5 days = 1 }
		}
		clr_global_flag = RAJ_afghan_war
	}
	option = {
		log = "[GetLogInfo]: event afghanistan_events.3 option afghanistan_events.3.b"
		name = afghanistan_events.3.b #They must be joking, Hindustan Zindabad!
		ai_chance = { base = 0 }
		FROM = { country_event = { id = afghanistan_events.4 days = 1 } }
	}
	after = {
		add_political_power = -200
	}
}

# RAJ refuses the peace demand
country_event = {
	id = afghanistan_events.4
	title = afghanistan_events.4.t
	desc = afghanistan_events.4.d
	picture = GFX_report_event_PRF_war

	is_triggered_only = yes

	option = {
		log = "[GetLogInfo]: event afghanistan_events.4 option afghanistan_events.4.a"
		name = afghanistan_events.4.a
		add_war_support = 0.10
	}
}

# AFG notification of RAJ agreeing to peace deal
country_event = {
	id = afghanistan_events.5
	title = afghanistan_events.5.t
	desc = afghanistan_events.5.d
	picture = GFX_report_event_PRF_war

	is_triggered_only = yes

	option = { #None shall ever again doubt our might!
		log = "[GetLogInfo]: event afghanistan_events.5 option afghanistan_events.5.a"
		name = afghanistan_events.5.a
		add_popularity = {
			ideology = paternal_autocrat
			popularity = 0.1
		}
	}
}

# First RAJ peace offer
country_event = {
	id = afghanistan_events.6
	title = afghanistan_events.6.t
	desc = afghanistan_events.6.d
	picture = GFX_report_event_PRF_war

	fire_only_once = yes

	trigger = {
		tag = RAJ
		has_war_with = AFG
		has_global_flag = RAJ_afghan_war
		AND = {
			controls_state = 442 #Peshawar
			controls_state = 445 #Quetta
		}
		surrender_progress < 0.1
		AFG = {
			owns_state = 442 #Peshawar
		}
	}

	mean_time_to_happen = {
		days = 1
	}

	option = { # Expel the Afghans from the occupied lands, nothing more.
		log = "[GetLogInfo]: event afghanistan_events.6 option afghanistan_events.6.a"
		name = afghanistan_events.6.a
		ai_chance = { base = 100 }
		AFG = {
			remove_state_core = 442 #Peshawar
			add_state_claim = 442 #Peshawar
			remove_state_claim = 445 #Quetta
			remove_state_claim = 444 #Baluchistan
			white_peace_with_ROOT = yes
		}
		RAJ = {
			transfer_state = 442 #Peshawar
		}
		hidden_effect = {
			country_event = { id = dominion_of_india_events.13 days = 6 random_days = 16 } #Status of Reconstruction of Quetta, TODO change trigger when AFG has content and this war is removed
			AFG = {
				country_event = afghanistan_events.9
				country_event = { id = afghanistan_events.13 days = 7 random_days = 36 }
			}
		}
		set_global_flag = AFG_lost_fifth_war
	}

	option = { #The war will not end until the snake Amanullah is forced from Kabul!
		log = "[GetLogInfo]: event afghanistan_events.6 option afghanistan_events.6.b"
		name = afghanistan_events.6.b
		ai_chance = { base = 0 }
		add_political_power = -100
		add_stability = -0.05
		set_country_flag = RAJ_refused_first_AFG_peace
	}
}

# Second RAJ peace event
country_event = {
	id = afghanistan_events.7
	title = afghanistan_events.7.t
	desc = afghanistan_events.7.d
	picture = GFX_report_event_PRF_war

	fire_only_once = yes

	trigger = {
		tag = RAJ
		has_war_with = AFG
		has_global_flag = RAJ_afghan_war
		has_country_flag = RAJ_refused_first_AFG_peace
		controls_state = 267 #Kabul
		controls_state = 445 #Quetta
		442 = { #Peshawar
			is_controlled_by = ROOT
			is_owned_by = AFG
		}
	}

	mean_time_to_happen = {
		days = 1
	}

	option = { # puppet
		log = "[GetLogInfo]: event afghanistan_events.7 option afghanistan_events.7.a"
		name = afghanistan_events.7.a
		AFG = {
			remove_state_core = 442 #Peshawar
			add_state_claim = 442 #Peshawar
			white_peace_with_ROOT = yes
		}
		RAJ = {
			transfer_state = 442 #Peshawar
			set_temp_variable = { target = AFG }
			puppet_country_without_changing_government = yes
		}
		hidden_effect = {
			country_event = { id = afghanistan_events.8 days = 1 }
			AFG = {
				country_event = afghanistan_events.9
			}
		}
		clr_country_flag = RAJ_refused_first_AFG_peace
		set_global_flag = AFG_lost_fifth_war
	}
}

# Afghanistan becomes a puppet
country_event = {
	id = afghanistan_events.8
	title = afghanistan_events.8.t
	desc = afghanistan_events.8.d
	picture = GFX_report_event_PRF_palace

	is_triggered_only = yes

	option = { #Keep Amanullah Khan
		log = "[GetLogInfo]: event afghanistan_events.8 option afghanistan_events.8.a"
		name = afghanistan_events.8.a
		ai_chance = { base = 50 }
	}

	option = { #Install Mohammad Nadir Khan
		log = "[GetLogInfo]: event afghanistan_events.8 option afghanistan_events.8.b"
		name = afghanistan_events.8.b
		ai_chance = { base = 50 }
		hidden_effect = {
			AFG = {
				retire_character = AFG_amanullah_khan
				retire_character = AFG_nasrullah_khan
				AFG_create_nadir = yes
			}
		}
		AFG = {
			custom_effect_tooltip = AFG_nadir_king_tt
		}
	}
}

# AFG notification of surrender
country_event = {
	id = afghanistan_events.9
	title = afghanistan_events.9.t
	picture = GFX_report_event_PRF_war

	immediate = {
		hidden_effect = {
			country_event = { id = afghanistan_events.25 random_hours = 100 days = 50 }
		}
		if = {
			limit = { has_idea = has_scripted_peace }
			remove_ideas = has_scripted_peace
		}
	}

	desc = {
		text = afghanistan_events.9.d
		trigger = {
			NOT = {
				is_subject_of = FROM
			}
		}
	}
	desc = {
		text = afghanistan_events.9.d.puppet
		trigger = {
			is_subject_of = FROM
		}
	}

	is_triggered_only = yes

	option = {
		log = "[GetLogInfo]: event afghanistan_events.9 option afghanistan_events.9.a"
		name = afghanistan_events.9.a
		clr_global_flag = RAJ_afghan_war
	}
}

###########################
# Later Afghanistan Events
###########################
# By anbory
###########################

###Shia muslims flee the war###
country_event = {
	id = afghanistan_events.10
	title = afghanistan_events.10.t
	desc = afghanistan_events.10.d

	trigger = {
		has_war = yes
	}

	is_triggered_only = yes

	option = {
		log = "[GetLogInfo]: event afghanistan_events.10 option afghanistan_events.10.a"
		name = afghanistan_events.10.a
		add_manpower = -5000
		PER = {
			country_event = { id = afghanistan_events.11 days = 1 }
		}
	}
}

###Shia muslims flee the war - PER message###
country_event = {
	id = afghanistan_events.11
	title = afghanistan_events.11.t
	desc = afghanistan_events.11.d

	is_triggered_only = yes

	option = { #Welcome them
		log = "[GetLogInfo]: event afghanistan_events.11 option afghanistan_events.11.a"
		ai_chance = { base = 70 }
		name = afghanistan_events.11.a
		add_manpower = 5000
	}

	option = { #Close the borders
		log = "[GetLogInfo]: event afghanistan_events.11 option afghanistan_events.11.b"
		ai_chance = { base = 30 }
		name = afghanistan_events.11.b
		AFG = {
			country_event = { id = afghanistan_events.12 days = 4 }
		}
	}
}

###Shia refugees return from Persia###
country_event = {
	id = afghanistan_events.12
	title = afghanistan_events.12.t
	desc = afghanistan_events.12.d

	is_triggered_only = yes

	option = {
		log = "[GetLogInfo]: event afghanistan_events.12 option afghanistan_events.12.a"
		name = afghanistan_events.12.a
		add_manpower = 5000
	}
}

###Political Instability after the war###
country_event = {
	id = afghanistan_events.13
	title = afghanistan_events.13.t
	desc = afghanistan_events.13.d

	is_triggered_only = yes

	option = { #Keep current leader
		log = "[GetLogInfo]: event afghanistan_events.13 option afghanistan_events.13.a"
		ai_chance = {
			base = 30
			modifier = {
				factor = 0
				has_game_rule = { rule = AFG_war option = AFG_WAR_NADIR_PATAUT }
			}
		}
		name = afghanistan_events.13.a
		add_stability = -0.4 #Deep political crisis
		custom_effect_tooltip = AFG_chaos_tooltip
		hidden_effect = {
			random_list = {
				40 = {
					country_event = { id = afghanistan_events.14 days = 31 } #Order Restored
				}
				60 = {
					country_event = { id = afghanistan_events.15 days = 31 } #Government Falls
					modifier = {
						factor = 0
						has_game_rule = { rule = AFG_war option = AFG_WAR_AMANULLAH_PATAUT }
					}
				}
			}
		}
	}

	option = { #New King
		log = "[GetLogInfo]: event afghanistan_events.13 option afghanistan_events.13.c"
		ai_chance = {
			base = 35
			modifier = {
				factor = 0
				has_game_rule = { rule = AFG_war option = AFG_WAR_AMANULLAH_PATAUT }
			}
		}
		name = afghanistan_events.13.c
		add_stability = -0.2
		hidden_effect = {
			AFG_create_nadir = yes
		}
		custom_effect_tooltip = AFG_nadir_king_tt
		AFG_mahmud_khan_sic = yes
		hidden_effect = {
			retire_character = AFG_amanullah_khan
			retire_character = AFG_nasrullah_khan
			country_event = { id = afghanistan_events.20 days = 7 }
		}
	}
}

###Order Restored###
country_event = {
	id = afghanistan_events.14
	title = afghanistan_events.14.t
	desc = afghanistan_events.14.d

	is_triggered_only = yes

	option = {
		log = "[GetLogInfo]: event afghanistan_events.14 option afghanistan_events.14.a"
		name = afghanistan_events.14.a
		add_stability = 0.2 #Initial recovery
	}
}

###Chaos in Afganistan###
country_event = {
	id = afghanistan_events.15
	title = afghanistan_events.15.t
	desc = afghanistan_events.15.d

	is_triggered_only = yes

	option = { #New King
		log = "[GetLogInfo]: event afghanistan_events.15 option afghanistan_events.15.a"
		name = afghanistan_events.15.a
		add_stability = 0.2
		hidden_effect = {
			AFG_create_nadir = yes
		}
		custom_effect_tooltip = AFG_nadir_king_tt
		AFG_mahmud_khan_sic = yes
		hidden_effect = {
			retire_character = AFG_amanullah_khan
			retire_character = AFG_nasrullah_khan
			country_event = { id = afghanistan_events.20 days = 7 }
		}
	}
}

### Reforms - Nadir Route###

### Nadir's Claims to the Throne###
country_event = {
	id = afghanistan_events.20
	title = afghanistan_events.20.t
	desc = afghanistan_events.20.d

	is_triggered_only = yes

	option = { # Call a jirga
		log = "[GetLogInfo]: event afghanistan_events.20 option afghanistan_events.20.a"
		name = afghanistan_events.20.a
		add_stability = 0.02
		country_event = { id = afghanistan_events.21 days = 7 }
	}
}

### Jirga decide what to do with Nadir###
country_event = {
	id = afghanistan_events.21
	title = afghanistan_events.21.t
	desc = afghanistan_events.21.d

	is_triggered_only = yes

	option = { # Accept him
		log = "[GetLogInfo]: event afghanistan_events.21 option afghanistan_events.21.a"
		name = afghanistan_events.21.a
		add_stability = 0.03
		add_political_power = 10
		country_event = { id = afghanistan_events.22 days = 70 }
	}
}

### Choose new HoG ###
country_event = {
	id = afghanistan_events.22
	title = afghanistan_events.22.t
	desc = afghanistan_events.22.d

	is_triggered_only = yes

	option = { # Muhammed Ghobar
		log = "[GetLogInfo]: event afghanistan_events.22 option afghanistan_events.22.a"
		ai_chance = { base = 30 }
		name = afghanistan_events.22.a
		AFG_mohammad_ghobar_sic = yes
		add_stability = -0.03
		set_temp_variable = { coalition_partner_var = token:social_liberal }
		add_to_coalition = yes
		add_popularity = {
			ideology = social_liberal popularity = 0.05
		}
	}

	option = { # Abdul Hadi Dawai
		log = "[GetLogInfo]: event afghanistan_events.22 option afghanistan_events.22.b"
		ai_chance = { base = 20 }
		name = afghanistan_events.22.b
		AFG_abdul_hadi_dawi_sic = yes
		add_stability = -0.03
		set_temp_variable = { coalition_partner_var = token:market_liberal }
		add_to_coalition = yes
		add_popularity = {
			ideology = market_liberal popularity = 0.05
		}
	}

	option = { # Mahmud Khan
		log = "[GetLogInfo]: event afghanistan_events.22 option afghanistan_events.22.c"
		ai_chance = { base = 50 }
		name = afghanistan_events.22.c
		AFG_mahmud_khan_sic = yes
		add_stability = -0.1
		add_popularity = {
			ideology = paternal_autocrat popularity = 0.05
		}
	}

	after = {
		country_event = { id = afghanistan_events.23 days = 140 }
	}
}

### Status of Amanullah's Reforms ###
country_event = {
	id = afghanistan_events.23
	title = afghanistan_events.23.t
	desc = afghanistan_events.23.d

	is_triggered_only = yes

	option = { # Only Agrarian reforms
		log = "[GetLogInfo]: event afghanistan_events.23 option afghanistan_events.23.a"
		ai_chance = { base = 0 }
		name = afghanistan_events.23.a
		add_stability = -0.05
		add_political_power = -50
		add_one_random_infrastructure = yes
		add_one_random_infrastructure = yes
	}

	option = { # Do Nothing
		log = "[GetLogInfo]: event afghanistan_events.23 option afghanistan_events.23.b"
		ai_chance = { base = 0 }
		name = afghanistan_events.23.b
		add_stability = 0.05
	}

	option = { # Full Reforms
		log = "[GetLogInfo]: event afghanistan_events.23 option afghanistan_events.23.c"
		ai_chance = { base = 10 }
		name = afghanistan_events.23.c
		add_stability = -0.15
		add_political_power = -150
		add_one_random_civilian_factory = yes
		add_one_random_civilian_factory = yes
		add_one_random_military_factory = yes
		add_one_random_infrastructure = yes
		add_one_random_infrastructure = yes
	}
}

###Indian sarrafs (money changers) left our country###
country_event = {
	id = afghanistan_events.24
	title = afghanistan_events.24.t
	desc = afghanistan_events.24.d

	trigger = {
		has_war_with = RAJ
	}

	is_triggered_only = yes

	option = {
		log = "[GetLogInfo]: event afghanistan_events.24 option afghanistan_events.24.a"
		name = afghanistan_events.24.a
		add_political_power = -20
		set_country_flag = AFG_sar_gone
	}
}

###War is over, sarrafs traders came back###
country_event = {
	id = afghanistan_events.25
	title = afghanistan_events.25.t
	desc = afghanistan_events.25.d

	fire_only_once = yes

	trigger = {
		tag = AFG
		NOT = {
			has_war_with = RAJ
		}
		has_country_flag = AFG_sar_gone
	}

	is_triggered_only = yes

	option = {
		log = "[GetLogInfo]: event afghanistan_events.25 option afghanistan_events.25.a"
		name = afghanistan_events.25.a
		add_political_power = 15
		clr_country_flag = AFG_sar_gone
	}
}

# Fifth Anglo-Afghan War
news_event = {
	id = afghanistan_events.30
	immediate = { log = "[GetLogInfo]: event afghanistan_events.30" }
	title = afghanistan_events.30.t
	desc = afghanistan_events.30.d
	picture = GFX_news_event_RAJ_afghan_war

	major = yes

	is_triggered_only = yes

	trigger = { wants_world_news = yes } #Global news event

	option = {
		name = afghanistan_events.30.a
		effect_tooltip = {
			add_named_threat = {
				threat = 1
				name = AFG_anglo_afghan_war_threat
			}
		}
	}
}

